<?php

namespace App\Model\Content;

use App\Model\CrudModel;

/**
 * @property int $id
 * @property string $content
 */
class NoticeModel extends CrudModel
{
    // 公告
    protected ?string $table = 'notice';

    protected array $adminPageListField = [
        'id', 'long_text_id', 'sort','show_status', 'title', 'created_at',
    ];

    public function addOne(array $data)
    {
        return $this->normalAddOne([
            'sort' => intval($data['sort'] ?? 0),
            'show_status' => intval($data['show_status']),
            'title' => trim($data['title']),
            'long_text_id' => intval($data['long_text_id']),
        ]);
    }

    public function updateById($id, array $data)
    {
        return $this->buildQuery(['id' => $id,])->update([
            'sort' => intval($data['sort'] ?? 0),
            'show_status' => intval($data['show_status']),
            'title' => trim($data['title']),
            'updated_at' => time(),
        ]);
    }

    protected function pageListSort($builder)
    {
        return $builder->orderByDesc('id');
    }

}